import { Component, OnInit, OnChanges, SimpleChange, SimpleChanges } from '@angular/core';
import { ActivatedRoute, Router, Params } from '@angular/router';
import { MainService } from '../../service/main.service';
import * as $ from 'jquery'
import { PageChangedEvent } from '../../../../node_modules/ngx-bootstrap';

@Component({
  selector: 'app-same-temp',
  templateUrl: './same-temp.component.html',
  styleUrls: ['./same-temp.component.css']
})
export class SameTempComponent implements OnInit {

  public msg:any
  public list;
  public webName;
  public lists;
  page:string;
  article:string;
  articleList=[];
  articleContent='';
  articleTitle='';
  RLName='';
  RAContent
  firstTitle='';
  leftH;
  rightH;
  firstLink:string='menu'
  publishDate
  mainUrl
  contentArray=[];
  returnedArray=[];
  rwfc:boolean=false;
  rwfcList=[];
  contentBtmImg='';
  contentRImg='';
  mapList=[];
  

  constructor(private atRoute:ActivatedRoute,private routeNow:Router,private service:MainService) {
   
    
    let _that=this
    atRoute.params.subscribe(function(data)
    {

          
    _that.articleList=[];
    _that.articleContent='';
    _that.articleTitle='';
    _that.RLName='';
    _that.page=_that.routeNow.url.split('/',2)[1]
    _that.article=_that.routeNow.url.split('/',3)[2]
    _that.mainUrl = service.picUrl

      
      if(_that.page=='sytzGsyj'){
        _that.service.getFirstFLList('4',res=>{
        _that.lists=res.list 
            if(_that.article){
              _that.service.getFromServ('/api/index/get_art'+'?id='+_that.article,{},res=>{
                console.log(res);
                $('.RAContent').html(res.article.content)
                _that.articleTitle=res.article.title
                _that.RLName=res.nav.s_title;_that.firstTitle=res.nav.f_title;
                _that.publishDate=res.article.publish_time
              },err=>{})
             }else{
              _that.changeR(data.id)
            }
          });
      }else if(_that.page=="news"){
        _that.service.getFirstFLList('3',res=>{
          _that.lists=res.list 
              if(_that.article){
                _that.service.getFromServ('/api/index/get_art'+'?id='+_that.article,{},res=>{
                  console.log(res);
                  $('.RAContent').html(res.article.content)
                  _that.articleTitle=res.article.title
                  _that.RLName=res.nav.s_title;_that.firstTitle=res.nav.f_title;
                  _that.publishDate=res.article.publish_time
                },err=>{})
               }else{
                _that.changeR(res.list[0].id)
              }
            });
      }else if(_that.page=="map"){
          _that.lists='' 
          _that.changeR('map')
      }
      else if(_that.page=="introduce"){
        _that.service.getFirstFLList('1',res=>{
          _that.lists=res.list 
              if(data.id==1){
                _that.changeR(res.list[1].id)
              }else{
                _that.changeR(res.list[5].id)
              }
              }
            );
      }
      else{
       
          _that.service.getFirstFLList(data.id,res=>{
            _that.lists=res.list 
            console.log(_that.atRoute.queryParams);
            _that.atRoute.queryParams.subscribe((params) => {
              if(params['art']){
                 _that.changeR (params['art']);
              }else{
                 _that.changeR(res.list[0].id)
              }
           
          });
        
           
        
          });
        
        
      }
// 左侧图标判断
    if(_that.page=="sytzGsyj"){
        // 公司业绩单独跳转
        // _that.firstLink='gongsiyeji'
          _that.webName = '../../../assets/img/gsyj.jpg'
          _that.contentBtmImg='../../assets/btmImgs/gsyj_l.jpg'
        _that.contentRImg='../../assets/btmImgs/gsyj_r.jpg'
          _that.service.getFirstFLList('4',res=>{
            // console.log(res);
            _that.lists=res.list 
            _that.changeR(_that.article)
            
          })

    }else if(_that.page=="news"){
        _that.webName = '../../../assets/img/xwzx.jpg';
        _that.contentBtmImg='../../assets/btmImgs/xw_l.jpg'
        _that.contentRImg='../../assets/btmImgs/xw_r.jpg' 
    }else if(_that.page=="map"){
        _that.webName = '../../../assets/img/qt.jpg'
        _that.contentBtmImg='../../assets/btmImgs/other_l.jpg'
        _that.contentRImg='../../assets/btmImgs/other_r.jpg'
    }else if(_that.page=="introduce"){
        _that.webName = '../../../assets/img/jtgk.jpg'
        _that.contentBtmImg='../../assets/btmImgs/jtgk_l.jpg'
        _that.contentRImg='../../assets/btmImgs/jtgk_r.jpg'
      
    }
    else{
      switch(data.id){
        case '1':
        // _that.firstLink='jituangaikuang'
        _that.webName = '../../../assets/img/jtgk.jpg'
        _that.contentBtmImg='../../assets/btmImgs/jtgk_l.jpg'
        _that.contentRImg='../../assets/btmImgs/jtgk_r.jpg'
        
        break;
      case '3':
      // _that.firstLink='xinwenzhongxin';
        _that.webName = '../../../assets/img/xwzx.jpg';
        _that.contentBtmImg='../../assets/btmImgs/xw_l.jpg'
        _that.contentRImg='../../assets/btmImgs/xw_r.jpg'
  
        break;
      case '4':
      // _that.firstLink='gongsiyeji'
        _that.webName = '../../../assets/img/gsyj.jpg'
        _that.contentBtmImg='../../assets/btmImgs/gsyj_l.jpg'
        _that.contentRImg='../../assets/btmImgs/gsyj_r.jpg'
        _that.page='4'
  
        break;
      case '5':
      // _that.firstLink='kejichuangxin'
        _that.webName = '../../../assets/img/kjcx.jpg'
        _that.contentBtmImg='../../assets/btmImgs/other_l.jpg'
        _that.contentRImg='../../assets/btmImgs/other_r.jpg'
  
        break;
      case '6':
      // _that.firstLink='qiyewenhua'
        _that.webName = '../../../assets/img/qywh.jpg'
        _that.contentBtmImg='../../assets/btmImgs/qywh_l.jpg'
        _that.contentRImg='../../assets/btmImgs/qywh_r.jpg'
  
        break;
      case '55':
      // _that.firstLink='lianxiwomen'
        _that.webName = '../../../assets/img/qt.jpg'
        _that.contentBtmImg='../../assets/btmImgs/other_l.jpg'
        _that.contentRImg='../../assets/btmImgs/other_r.jpg'
        break;
        case '7':
        _that.webName = '../../../assets/img/rlzy.jpg'
        _that.contentBtmImg='../../assets/btmImgs/xw_l.jpg'
        _that.contentRImg='../../assets/btmImgs/xw_r.jpg'
        break;
        case '72':
        _that.webName = '../../../assets/img/rlzy.png'
        _that.contentBtmImg='../../assets/btmImgs/xw_l.jpg'
        _that.contentRImg='../../assets/btmImgs/xw_r.jpg'
        break;  
      }
    }
    
    });
}


  ngOnInit() {}


changeR($event){
  // console.log($event);
  
  this.articleList=[];
  this.articleTitle='';
  this.returnedArray=[];
  $(".RAContent").html('')
  if($event==35){
    this.rwfc=true
    this.service.getFromServ('/api/index/get_graceful',{},res=>{
      console.log(res.list);
      this.rwfcList=res.list
    },err=>{})
  }else if($event=='map'){
    this.service.getFromServ('/api/index/get_map',{},res=>{
      console.log(res);
      this.mapList = res.list;
      this.RLName = '网站地图'
      
    },err=>{})
  }else{
    this.rwfc=false;
    this.service.getFromServ('/api/index/get_art_list'+'?id='+$event,{},res=>{
      // console.log(res);
        // this.articleList=res.art_list;
        this.contentArray=res.art_list;
        this.returnedArray=this.contentArray.slice(0,15)
        // console.log(this.contentArray);
        
        this.RLName=res.nav.s_title;this.firstTitle=res.nav.f_title;
        if(res.article[0]){
          $(".RAContent").html(res.article[0].content)
          this.articleTitle=res.article[0].title
          this.publishDate=res.article[0].publish_time
        }
       
    },err=>{})
  }
   
}
pageChanged(event: PageChangedEvent): void {
  // console.log(event);
  // let maximum=Math.ceil(this.contentArray.length/12)
  const startItem = (event.page - 1) * event.itemsPerPage;
  const endItem = event.page * event.itemsPerPage;
  this.returnedArray = this.contentArray.slice(startItem, endItem);
}

changeFont($event){
// console.log($event);
switch($event){
  case 1 :
  $('.RAContent').css('font-size','16px');
  break;
  case 2 :
  $('.RAContent').css('font-size','14px');
  break;
  case 3 :
  $('.RAContent').css('font-size','12px');
  break;
  case 4 :
  window.print()
  
  break;
}}

showNews(arg){

  this.service.getFromServ('/api/index/get_art'+'?id='+arg,{},res=>{
    console.log(res);
    $('.RAContent').html(res.article.content)
    this.articleTitle=res.article.title
    this.RLName=res.nav.s_title;this.firstTitle=res.nav.f_title;
    this.publishDate=res.article.publish_time
  },err=>{})

}

goToPage(a,b){
  this.routeNow.navigateByUrl('/menu/'+a+'?art='+b)
}




}

